//Copyright 2010 Balazs Keri, Imre Keri
//
//This file is part of FireworksCreator.
//
//FireworksCreator is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.
//
//FireworksCreator is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with FireworksCreator.  If not, see <http://www.gnu.org/licenses/>.
//
#ifndef _DISPLAYVIEW_H
#define _DISPLAYVIEW_H
//
#include <QWidget>
#include <QState>
#include "view.h"
//
class DisplayView;
class SetDocTransition:public QSignalTransition
{
   Q_OBJECT
public:
   SetDocTransition(DisplayView *view);
protected:
   void onTransition(QEvent *event);
private:
   DisplayView *view;
};
class ClearDocTransition:public QSignalTransition
{
   Q_OBJECT
public:
   ClearDocTransition(DisplayView *view);
protected:
   void onTransition(QEvent *event);
private:
   DisplayView *view;
};
class BoolCheckTransition:public QSignalTransition
{
   Q_OBJECT
public:
   BoolCheckTransition(unsigned int param,bool guard_value,QObject *sender,const char *signal,QState *sourceState=0)
   :
      QSignalTransition(sender,signal,sourceState),
      param(param),
      guard_value(guard_value)
   {
   }
protected:
   bool eventTest(QEvent *e)
   {
      if(!QSignalTransition::eventTest(e))
         return false;
      QStateMachine::SignalEvent *se=static_cast<QStateMachine::SignalEvent*>(e);
      return (se->arguments().at(param).toBool()==guard_value);
   }
private:
   unsigned int param;
   bool guard_value;
};
//
class PlayerWindow;
class PlayerControl;
class QStateMachine;
class DisplayView:public QWidget,public View
{
   Q_OBJECT
   Q_DISABLE_COPY(DisplayView)
   friend class SetDocTransition;
   friend class ClearDocTransition;
//construction
public:
   DisplayView(QWidget *parent=0);
   ~DisplayView();
//signals
signals:
   void doc_changed();
   void doc_cleared();
//slots
protected slots:
   void on_timer_timeout();
   void on_player_current_time_changed(unsigned int time);
   void on_player_start_time_changed(unsigned int time);
   void on_player_stop_time_changed(unsigned int time);
//View overrides
protected:
   void handle_set_attr_group();
   void handle_attr_event(AttrEvent *event);
   void handle_post_primitive_group(const PrimitiveGroup &p_primitive_group);
//data
private:
   PlayerWindow *player_window;
   PlayerControl *player_control;
   QTimer *timer;
   QStateMachine *machine;
private:
   static unsigned int const time_update_interval=50;
//util
private:
   void create_machine();
};
//
#endif
